package com.yimi.yinhepda.entity.response;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author 000432
 * @date 2017/4/6
 * PDA获取装车任务单号列表  主单信息
 */
public class QueryLoadDetailBillcode implements Comparable<Object>, Serializable {
    /**
     * 运单号/包号
     */
    private String waybillNo;
    /**
     * 开单件数
     */
    private Integer srcPiecesNum;
    /**
     * 库存件数
     */
    private Integer piecesNum;
    /**
     * 重量  ??
     */
    private BigDecimal weight;
    /**
     * 体积
     */
    private BigDecimal volume;
    /**
     * 计费重量
     */
    private BigDecimal chargedWeight;
    /**
     * 运单路由
     */
    private String waybillRoute;
    /**
     * 包号
     */
    private String packageNo;
    /**
     * 到达库区
     */
    private String areaCode;
    /**
     * 单据类型：1 运单，2 包
     */
    private Integer billType;
    /**
     * 配载单号
     */
    private String stowageNo;
    /**
     * 车牌号
     */
    private String carNo;
    /**
     * 强扫标记   空不是强扫   2是强扫
     */
    private transient String remark = "";
    private boolean isBigTicket = false;
    /**
     * 必走货字段 1-必走货，2-串货，3-标准,4-跨越
     */
    private String goodsPriority;
    /**
     * 产品类型：CP24-时,CP13-优
     */
    private String productType;
    /**
     * 动态路由
     */
    private String dynamicRoute;
    /**
     * 运单子单集合
     */
    private List<QueryLoadDetailChildBillcode> childList;
    /**
     * 新旧重量壁纸
     */
    private BigDecimal weightRate;
    /**
     * 新旧体积壁纸
     */
    private BigDecimal volumeRate;
    /**
     * 运单类型:1-正常单  2-整车单,3-外传单 4-内转单 5-退货单,  6-签回单
     */
    private String waybillType;

    public QueryLoadDetailBillcode(String stowageNo, String remark, String carNo, Integer billType, String areaCode, String packageNo,
                                   String waybillRoute, BigDecimal volume, BigDecimal chargedWeight, BigDecimal weight, Integer piecesNum, Integer srcPiecesNum,
                                   String waybillNo) {
        this.stowageNo = stowageNo;
        this.remark = remark;
        this.carNo = carNo;
        this.billType = billType;
        this.areaCode = areaCode;
        this.packageNo = packageNo;
        this.waybillRoute = waybillRoute;
        this.volume = volume;
        this.chargedWeight = chargedWeight;
        this.weight = weight;
        this.piecesNum = piecesNum;
        this.srcPiecesNum = srcPiecesNum;
        this.waybillNo = waybillNo;
    }

    public QueryLoadDetailBillcode() {
    }

    public String getWaybillType() {
        return waybillType;
    }

    public void setWaybillType(String waybillType) {
        this.waybillType = waybillType;
    }

    public BigDecimal getWeightRate() {
        return weightRate;
    }

    public void setWeightRate(BigDecimal weightRate) {
        this.weightRate = weightRate;
    }

    public BigDecimal getVolumeRate() {
        return volumeRate;
    }

    public void setVolumeRate(BigDecimal volumeRate) {
        this.volumeRate = volumeRate;
    }

    public String getDynamicRoute() {
        return dynamicRoute;
    }

    public void setDynamicRoute(String dynamicRoute) {
        this.dynamicRoute = dynamicRoute;
    }

    public String getProductType() {
        return productType;
    }

    public void setProductType(String productType) {
        this.productType = productType;
    }

    public String getGoodsPriority() {
        return goodsPriority;
    }

    public void setGoodsPriority(String goodsPriority) {
        this.goodsPriority = goodsPriority;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getStowageNo() {
        return stowageNo;
    }

    public void setStowageNo(String stowageNo) {
        this.stowageNo = stowageNo;
    }

    public String getCarNo() {
        return carNo;
    }

    public void setCarNo(String carNo) {
        this.carNo = carNo;
    }

    public String getWaybillNo() {
        return waybillNo;
    }

    public void setWaybillNo(String waybillNo) {
        this.waybillNo = waybillNo;
    }

    public Integer getSrcPiecesNum() {
        if (srcPiecesNum == null) {
            srcPiecesNum = 0;
        }
        return srcPiecesNum;
    }

    public void setSrcPiecesNum(Integer srcPiecesNum) {
        this.srcPiecesNum = srcPiecesNum;
    }

    public Integer getPiecesNum() {
        if (piecesNum == null) {
            piecesNum = 0;
        }
        return piecesNum;
    }

    public void setPiecesNum(Integer piecesNum) {
        this.piecesNum = piecesNum;
    }

    public BigDecimal getWeight() {
        if (weight == null) {
            weight = BigDecimal.ZERO;
        }
        return weight;
    }

    public void setWeight(BigDecimal weight) {
        this.weight = weight;
    }

    public BigDecimal getVolume() {
        if (volume == null) {
            volume = BigDecimal.ZERO;
        }
        return volume;
    }

    public void setVolume(BigDecimal volume) {
        this.volume = volume;
    }

    public BigDecimal getChargedWeight() {
        if (chargedWeight == null) {
            chargedWeight = BigDecimal.ZERO;
        }
        return chargedWeight;
    }

    public void setChargedWeight(BigDecimal chargedWeight) {
        this.chargedWeight = chargedWeight;
    }

    public String getWaybillRoute() {
        return waybillRoute;
    }

    public void setWaybillRoute(String waybillRoute) {
        this.waybillRoute = waybillRoute;
    }

    public String getPackageNo() {
        return packageNo;
    }

    public void setPackageNo(String packageNo) {
        this.packageNo = packageNo;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public Integer getBillType() {
        if (billType == null) {
            billType = 0;
        }
        return billType;
    }

    public void setBillType(Integer billType) {
        this.billType = billType;
    }

    public List<QueryLoadDetailChildBillcode> getChildList() {
        return childList;
    }

    public void setChildList(List<QueryLoadDetailChildBillcode> childList) {
        this.childList = childList;
    }

    /**
     * 获得已扫数量
     */
    public int getScanCount() {
        if (childList == null || childList.size() == 0) {
            return 0;
        }
        int count = 0;
        for (QueryLoadDetailChildBillcode item : childList) {
            if (item.getFlag() == 1) {
                count++;
            }
        }
        return count;
    }

    /**
     * 差异=扫描-开单   装车
     */
    public int getDifference() {
        return getScanCount() - (isBigTicket() ? 1 : srcPiecesNum);
    }

    public int getType() {
        int dif = getDifference();
        if (getScanCount() == 0) {
            return 1;//白色
        } else if (dif < 0) {
            return 0;//红色
        } else if (dif > 0) {
            return 2;//黄色
        } else {
            return 3;//绿色
        }
    }

    public boolean isBigTicket() {
        return isBigTicket;
    }

    public void setBigTicket(boolean mBigTicket) {
        isBigTicket = mBigTicket;
    }

    @Override
    public int compareTo(Object o) {
        return this.getType() - ((QueryLoadDetailBillcode) o).getType();
    }

    public static QueryLoadDetailBillcode parse(QueryUnLoadDetailBillcode mQueryUnLoadDetailBillcode) {
        QueryLoadDetailBillcode mQueryLoadDetailBillcode =
                new QueryLoadDetailBillcode(mQueryUnLoadDetailBillcode.getStowageNo(), mQueryUnLoadDetailBillcode.getRemark(),
                        mQueryUnLoadDetailBillcode.getCarNo(), mQueryUnLoadDetailBillcode.getBillType(), mQueryUnLoadDetailBillcode.getAreaCode(),
                        mQueryUnLoadDetailBillcode.getPackageNo(), mQueryUnLoadDetailBillcode.getWaybillRoute(), mQueryUnLoadDetailBillcode.getVolume(),
                        mQueryUnLoadDetailBillcode.getChargedWeight(), mQueryUnLoadDetailBillcode.getWeight(), mQueryUnLoadDetailBillcode.getPiecesNum(),
                        mQueryUnLoadDetailBillcode.getSrcPiecesNum(), mQueryUnLoadDetailBillcode.getWaybillNo());
        mQueryLoadDetailBillcode.setChildList(mQueryUnLoadDetailBillcode.getChildList());
        return mQueryLoadDetailBillcode;
    }
}
